<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title th:text="${title}">测试页面</title>
    <style>
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            max-width: 800px;
            margin: 0 auto;
            background: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        .header {
            text-align: center;
            color: #333;
            margin-bottom: 30px;
        }
        .api-section {
            margin: 20px 0;
            padding: 20px;
            background: #f8f9fa;
            border-radius: 5px;
        }
        .btn {
            background: #007bff;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            margin: 5px;
        }
        .btn:hover {
            background: #0056b3;
        }
        .result {
            margin-top: 15px;
            padding: 15px;
            background: #e9ecef;
            border-radius: 5px;
            font-family: monospace;
            white-space: pre-wrap;
            display: none;
        }
        .timestamp {
            color: #666;
            font-size: 14px;
            margin-top: 20px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1 th:text="${title}">OralPractice 测试页面</h1>
            <p th:text="${message}">欢迎使用口语练习系统！</p>
        </div>

        <div class="api-section">
            <h3>API 接口测试</h3>
            <button class="btn" onclick="testHelloApi()">测试 Hello API</button>
            <button class="btn" onclick="testStatusApi()">测试 Status API</button>
            <div id="apiResult" class="result"></div>
        </div>

        <div class="api-section">
            <h3>系统信息</h3>
            <p><strong>应用名称:</strong> OralPractice</p>
            <p><strong>版本:</strong> 1.0.0</p>
            <p><strong>状态:</strong> <span style="color: green;">运行中</span></p>
        </div>

        <div class="timestamp">
            <p>页面加载时间: <span th:text="${timestamp}"></span></p>
        </div>
    </div>

    <script>
        async function testHelloApi() {
            try {
                const response = await fetch('/test/api/hello');
                const data = await response.json();
                showResult(JSON.stringify(data, null, 2));
            } catch (error) {
                showResult('错误: ' + error.message);
            }
        }

        async function testStatusApi() {
            try {
                const response = await fetch('/test/api/status');
                const data = await response.json();
                showResult(JSON.stringify(data, null, 2));
            } catch (error) {
                showResult('错误: ' + error.message);
            }
        }

        function showResult(text) {
            const resultDiv = document.getElementById('apiResult');
            resultDiv.textContent = text;
            resultDiv.style.display = 'block';
        }

        // 页面加载完成后自动测试状态API
        window.onload = function() {
            setTimeout(testStatusApi, 1000);
        };
    </script>
</body>
</html>